



import BaseHelper from "./BaseHelper";
import ChannelEvent from "./ChannelEvent";
import ChannelUtils from "./ChannelUtils";

export default class OppoHelper extends BaseHelper {


    protected zsConfig = {
        zs_version: '1.0',
        zs_jump_switch: 1,//是否显示格子广告
        zs_switch: 0,//误触总开关(1-开 0-关)
        zs_banner_city: 0,
        zs_banner_system: '',
        zs_native_gap_time: 30,//游戏过程中间隔X秒弹出激励视频弹窗，同时展 示嵌入式原生，
        zs_banner_native_time: 30,//banner型原生每x秒刷新一次，接入开关zs_banner_native_time（单位：秒）ok
        zs_native_click_switch: 0,
        zs_banner_native_switch: 0,//为1时展示原生，为0时展示banner
        zs_native_touch_switch: 0,//为1时，关闭按钮尺寸为40*40，实际可点击范围为32*32；为0时点击范围为40*40
        zs_native_next_limit: 0,//插屏原生广告页面，原生卡片和“点击查看”按钮中间新增一个“下一步”按钮（如上图），按钮是否展示接入开关zs_native_next_limit
        zs_native_close_num: 0,//
        zs_native_limit: 0,//游戏进行页面每隔30s弹出一次插屏式原生广告
        zs_jump_time: 0,//原生关闭按钮接入延迟开关 单位毫秒
        zs_native_slide_switch: 0,//开启时滑动屏幕过程中碰到广告区域也直接进入广告，关闭时正常点击进入
        zs_onemin_show_ad_switch: 1//1 不展示，0 展示
    }

    constructor() {
        super();
        this.setVersion('1.0')
        // this.login()
        // this.loadConfig();
    }


    login(isInit: boolean = true) {
        let zsSdk = window['zs'].sdk
        zsSdk.login((openid) => {
            console.log(' msg ', openid)
            zsSdk.init(openid)
        }, (err) => {
            console.log('login error ', err)
            setTimeout(() => {
                this.login(isInit)
            }, 3000);
        })
    }
    loadConfig() {
        let zsSdk = window['zs'].sdk
        zsSdk.loadCfg((result) => {
            this.zsConfig = result;
            console.log(' result === ', result)

            //test ------------------
            // this.zsConfig.zs_jump_switch = 1;
            // this.zsConfig.zs_native_limit = 1;
            // this.zsConfig.zs_banner_native_switch = 1;
            // this.zsConfig.zs_native_close_num = 1;

            if (this.zsConfig.zs_onemin_show_ad_switch == 1) {
                setTimeout(() => {
                    this.zsConfig.zs_onemin_show_ad_switch = 0;
                }, 60000);
            }
            ChannelEvent.instance().emit(ChannelEvent.LOAD_CONFIG)
        }, (err) => {
            console.log(' err === ', err)
            setTimeout(() => {
                this.loadConfig()
            }, 3000);
        });
    }
    getzs_native_gap_time() {
        if (this.zsConfig.zs_native_gap_time) {
            return this.zsConfig.zs_native_gap_time
        }
        return 0;
    }
    getBannerWitch() {
        if (this.zsConfig.zs_banner_native_switch) {
            return this.zsConfig.zs_banner_native_switch
        }
        return 0;
    }
    hasNativeTouchSwitch() {
        return this.zsConfig.zs_native_touch_switch == 1
    }
    getNativeBannerRefreshTime() {
        if (this.zsConfig.zs_banner_native_time) {
            return this.zsConfig.zs_banner_native_time
        }
        return 30;
    }
    getNativeCloseNum() {
        if (this.zsConfig.zs_native_close_num) {
            return this.zsConfig.zs_native_close_num
        }
        return 0;
    }
    isVersion() {
        return ChannelUtils.compareVersion(this.verson, this.zsConfig.zs_version) == 1
    }

    isJumpSwitchOpen() {
        return this.isVersion() && this.zsConfig.zs_jump_switch == 1
    }

    hasNativeLimit() {
        return this.isVersion() && this.zsConfig.zs_native_limit == 1
    }

    noOneMinAdLimit() {
        return this.zsConfig.zs_onemin_show_ad_switch == 0;
    }

    getJumpTime() {
        if (this.zsConfig.zs_jump_time) {
            return this.zsConfig.zs_jump_time;
        }
        return 0
    }

    isOpenNativeErrorClick() {
        return this.isVersion() && this.zsConfig.zs_native_click_switch == 1
    }

    getNativeSlide() {
        if (this.zsConfig.zs_native_slide_switch) {
            return this.zsConfig.zs_native_slide_switch
        }
        return 0;
    }
}